package org.design.serial.dao;

import org.design.serial.entity.SerialInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.io.Serializable;

/**
 * SerialRuleDao
 *
 * @author 樊温军
 * @date 2025/6/16 上午9:02
 */
public interface SerialInfoDao extends JpaRepository<SerialInfo, String>, Serializable {
    @Query("select s from SerialInfo s where s.ruleId = :id and s.keyword = :keyWord")
    SerialInfo getByRuleIdAndKeyWord(@Param("id") Long id, @Param("keyWord") String keyWord);

    @Modifying
    @Query("update SerialInfo s set s.currentCodeNumber = :replace, s.currentSerialNumber = :newCurrentSerialNumber where s.id = :id and s.currentSerialNumber = :currentSerialNumber")
    int updateByNumAndId(@Param("replace") String replace, @Param("id") Long id, @Param("newCurrentSerialNumber") Integer newCurrentSerialNumber, @Param("currentSerialNumber") Integer currentSerialNumber);
}
